package com.baize.minespace.controller;


import com.baize.minespace.pojo.Tags;
import com.baize.minespace.service.TagsService;
import com.baize.minespace.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 标签信息表 前端控制器
 * </p>
 *
 * @author baize
 * @since 2024-04-15
 */
@RestController
@RequestMapping("/tags")
public class TagsController {
    @Autowired
    private TagsService tagsService;

    @ApiModelProperty("新增标签信息表")
    @ApiOperation(value = "新增标签信息表", notes = "新增标签信息表")
    @PostMapping("add")
    public Result<Boolean> addTags(@RequestBody Tags tags){
        return Result.success(tagsService.save(tags));
    }

    @ApiModelProperty("删除标签信息表")
    @ApiOperation(value = "删除标签信息表", notes = "删除标签信息表")
    @GetMapping ("delete/{id}")
    public Result<Boolean> deleteTags(@PathVariable(value = "id") Integer id) {
        return Result.success(tagsService.removeById(id));
    }

    @ApiModelProperty("修改标签信息表")
    @ApiOperation(value = "修改标签信息表", notes = "修改标签信息表")
    @PostMapping("update")
    public Result<Boolean> updateTags(@RequestBody Tags tags) {
        return Result.success(tagsService.updateById(tags));
    }

    @ApiModelProperty("查询标签信息表")
    @GetMapping("select/{id}")
    public Result<Tags> selectTags(@PathVariable(value = "id") Integer id) {
        return Result.success(tagsService.getById(id));
    }

    @ApiModelProperty("分页查询标签信息表")
    @ApiOperation(value = "分页查询标签信息表", notes = "分页查询标签信息表")
    @GetMapping("page/{rows}/{page}")
    public Result<IPage<Tags>> selectTagsPage(
        @PathVariable(value = "rows") Integer rows,
        @PathVariable(value = "page") Integer page,
        @RequestBody Tags tags
    ) {
        return tagsService.selectTagsPage(rows, page, tags);
    }
}
